package com.api.weavernorth.LogWeaTable.web;

import com.alibaba.fastjson.JSONObject;
import com.api.weavernorth.LogWeaTable.pojo.logdataPojo;
import com.api.weavernorth.LogWeaTable.service.Impl.LogDataServiceImpl;
import com.api.weavernorth.LogWeaTable.service.LogRecordService;
import com.api.weavernorth.LogWeaTable.service.Impl.LogRecordServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.weavernorth.util.Logger4jUtil;
import org.apache.log4j.Logger;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: BruseeWang
 * @Date: 2021/12/08 13:23
 * @Description: 日志记录表api
 */
@Path("/LogWeaTable")
public class LogRecordApi {

    private LogRecordService getService(User user) {
        return (LogRecordServiceImpl) ServiceUtil.getService(LogRecordServiceImpl.class, user);
    }

    /**
     * 获取weatable的值
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/weatableLog")
    @Produces({MediaType.TEXT_PLAIN})
    public String weatableDemo(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            //获取当前用户
            User user = HrmUserVarify.getUser(request, response);
            apidatas.putAll(getService(user).weatableLog(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /**
     * 获取高级搜索条件
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/weatableConditonLog")
    @Produces({MediaType.TEXT_PLAIN})
    public String weatableConditonDemo(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            //获取当前用户
            User user = HrmUserVarify.getUser(request, response);
            apidatas.putAll(getService(user).weatableConditonLog(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }
    /**
     * 获取所有的日志
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getAllLog")
    @Produces({MediaType.TEXT_PLAIN})
    public void getAllLog(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Logger log = Logger4jUtil.getLoggerByName("/api/weavernorth/LogWeaTable/");
        LogDataServiceImpl service=new LogDataServiceImpl();
        Map<String,Object> params=new HashMap<>();
        List<logdataPojo> log_List = service.Operation_LogData(log,params,true);
    }
}
